﻿using SIG.Infrastructure.Configs;
using SIG.Model.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace SIG.Web.Models
{
    /// <summary>
    /// 系统级管理过滤
    /// </summary>
    public class SIGAuthSysAttribute : AuthorizeAttribute
    {

        protected virtual CustomPrincipal CurrentUser
        {
            get { return HttpContext.Current.User as CustomPrincipal; }
        }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (!filterContext.HttpContext.Request.IsAuthenticated)
            {
                base.OnAuthorization(filterContext);
            }
            else
            { 
                    if (!CurrentUser.IsInRole("系统管理员") || !(CurrentUser.UserId.ToString() == SettingsManager.User.Founder))
                    {
                        filterContext.Result = new RedirectToRouteResult(new
                            RouteValueDictionary(new { controller = "Account", action = "AccessDenied" }));                        
                    }            
               
            }


        }
    }
}
